package cn.wolfcode.luowowo2.articleserver.service.imp;

import cn.wolfcode.luowowo2.article.domain.StrategyCommend;
import cn.wolfcode.luowowo2.article.mapper.StrategyCommendMapper;
import cn.wolfcode.luowowo2.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo2.common.query.StrategyCommendQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Albert on 2019/7/14.
 */
@Service
public class StrategyCommendServiceImpl implements IStrategyCommendService{
    @Autowired
    private StrategyCommendMapper mapper;

    @Override
    public PageInfo<StrategyCommend> query(StrategyCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyCommend> list = mapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void saveOrUpdate(StrategyCommend commend) {
        if (commend.getId()==null) {
            mapper.insert(commend);
        }else {
            mapper.updateByPrimaryKey(commend);
        }
    }

    @Override
    public List<StrategyCommend> getTop5Commends() {
        return mapper.selectTop5Commends();
    }
}
